<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "goods_attr".
 *
 * @property int $id
 * @property string $goods_no 商品编号
 * @property string $name 属性名称
 * @property string $attr_id 属性ID
 * @property string $attr_val 单选或者多选属性的值
 * @property string $val 属性值
 * @property int $sort 排序
 * @property int $addtime
 */
class GoodsAttr extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods_attr';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['goods_no', 'name', 'val', 'addtime'], 'required'],
            [['goods_no', 'sort', 'addtime'], 'integer'],
            [['name'], 'string', 'max' => 80],
            [['val'], 'string', 'max' => 150],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'goods_no' => '商品编号',
            'name' => '属性名称',
            'val' => '属性值',
            'sort' => '排序',
            'addtime' => 'Addtime',
        ];
    }
    
    public static function getAttrByGoodsno($goodsno){
        $sql = "select * from goods_attr where goods_no = $goodsno";
        $command = \Yii::$app->db->createCommand($sql);
    	return $model = $command->queryAll();
    }
    
    public static function getAttrByGoodsnoAndAttrid($goodsno,$attrid){
        $sql = "select * from goods_attr where goods_no = $goodsno and attr_id=$attrid";
        $command = \Yii::$app->db->createCommand($sql);
    	return $model = $command->queryOne();
    }
}
